#include<iostream>
#include<algorithm>
using namespace std;
const int N = 310, M = N * N;
struct Edge
{
	int a, b, w;
	bool operator<(const Edge& t)const {
		return w < t.w;
	}
}edge[M];
int p[N];
int n, m;
int find(int x)
{
	if (x != p[x]) {
		p[x] = find(p[x]);
	}
	return p[x];
}
int main()
{
	cin >> n >> m;
	for (int i = 0; i < m; i++) {
		int a, b, w;
		cin >> a >> b >> w;
		edge[i] = { a,b,w };
	}
	sort(edge, edge + m);
	for (int i = 1; i <= n; i++) {
		p[i] = i;
	}
	int ans = 0;
	for (int i = 0; i < m; i++) {
		int a = find(edge[i].a);
		int b = find(edge[i].b);
		int w = edge[i].w;
		if (a != b) {
			p[a] = b;
			ans = w;
		}
	}
	cout << n - 1 << " " << ans << endl;
	return 0;
}